using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Admin_Admin_Stock_StockNumber : Admin, IRequiresSessionState
{
	private string linkHead = "";
	private string beforeUrl = "Admin_Stock_StockNumber.aspx?MenuID=5&MenuName=库存管理&FileName=库存状况表";
	protected Literal ltrTitle;
	protected HtmlTable table_item;
	protected DropDownList ddlProdcutType;
	protected DropDownList ddlDetailSearchType;
	protected TextBox DetailSearchName;
	protected Button btnSearch;
	protected Repeater rptList;
	protected Literal ltrPagePanel;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (!base.admin.CheckAdminPower(45))
			{
				base.WriteLog("Modidy", Language.GetAdminMsg("Log/Access", "0"), "Admin_Stock_StockNumber");
				base.WriteRightErrMsg();
			}
			this.BindData();
		}
	}
	protected string GetQuery()
	{
		string text = " where 1=1";
		string text2 = Fetch.Get("ProductType");
		if (!string.IsNullOrEmpty(text2))
		{
			this.ddlProdcutType.ddlSelect(text2);
		}
		else
		{
			text2 = this.ddlProdcutType.SelectedValue.Trim();
		}
		if (!string.IsNullOrEmpty(text2) && text2 != "0")
		{
			text = text + " and ProductType=" + text2;
			this.linkHead = this.linkHead + "&ProductType=" + text2;
		}
		string text3 = Fetch.Get("DetailSearch");
		if (!string.IsNullOrEmpty(text3))
		{
			this.ddlDetailSearchType.ddlSelect(text3);
		}
		else
		{
			text3 = this.ddlDetailSearchType.SelectedValue;
		}
		string text4 = Fetch.Get("DetailSearchName");
		if (!string.IsNullOrEmpty(text4))
		{
			this.DetailSearchName.Text = text4;
		}
		else
		{
			text4 = this.DetailSearchName.Text;
		}
		if (!string.IsNullOrEmpty(text4) && !string.IsNullOrEmpty(text3))
		{
			string text5 = text3;
			if (text5 != null)
			{
				if (!(text5 == "product_name"))
				{
					if (!(text5 == "saler_name"))
					{
						if (text5 == "product_class")
						{
							text = text + " and ClassID in (Select ClassID From [HLShop_Class] Where ClassName like '%" + text4 + "%')";
						}
					}
					else
					{
						text = text + " and SalerID in (select UserID from HL_User where UserName like '%" + text4 + "%')";
					}
				}
				else
				{
					text = text + " and ProductName like '%" + text4 + "%'";
				}
			}
			string text6 = this.linkHead;
			this.linkHead = string.Concat(new string[]
			{
				text6,
				"&DetailSearch=",
				text3,
				"&DetailSearchName=",
				base.Server.UrlEncode(text4)
			});
		}
		return text;
	}
	private string GetQueryByOrder()
	{
		return "order by ProductID desc";
	}
	public void BindData()
	{
		string query = this.GetQuery();
		string queryByOrder = this.GetQueryByOrder();
		int num = 0;
		if (Fetch.Get("pageindex") != null)
		{
			num = Convert.ToInt32(Fetch.GetID("pageindex").ToString());
			if (num == 0)
			{
				num = 1;
			}
		}
		string text = " from HLShop_Product";
		int num2 = 10;
		int listCount = BLLInstance.BllClientByPage.GetListCount("select count(*)" + text + query);
		int startIndex = (num - 1) * num2 + 1;
		int endIndex = num * num2;
		string str = "ROW_NUMBER() OVER (" + queryByOrder + ") as row,(select UserName from HL_User where UserID=HLShop_Product.SalerID) as SalerName,(select ClassName from HLShop_Class where ClassID=HLShop_Product.ClassID) as ClassName,* ";
		string strSQL = "select " + str + text + query;
		DataTable listPage = BLLInstance.BllClientByPage.GetListPage(strSQL, "row", startIndex, endIndex);
		this.rptList.DataSource = listPage;
		this.rptList.DataBind();
		decimal d = 0m;
		decimal d2 = 0m;
		for (int i = 0; i < this.rptList.Items.Count; i++)
		{
			int num3 = i + 1;
			if (num > 0)
			{
				num3 = (num - 1) * num2 + num3;
			}
			Label label = (Label)this.rptList.Items[i].FindControl("lblRow");
			label.Text = num3.ToString();
			HiddenField hiddenField = (HiddenField)this.rptList.Items[i].FindControl("hfCount");
			HiddenField hiddenField2 = (HiddenField)this.rptList.Items[i].FindControl("hfStandPrice");
			Label label2 = (Label)this.rptList.Items[i].FindControl("lblMoney");
			if (label2 != null)
			{
				if (!string.IsNullOrEmpty(hiddenField.Value) && !string.IsNullOrEmpty(hiddenField2.Value))
				{
					decimal d3 = Convert.ToDecimal(hiddenField2.Value);
					int value = Convert.ToInt32(hiddenField.Value);
					decimal d4 = d3 * value;
					label2.Text = d4.ToString();
					d2 += d4;
					d += value;
				}
			}
		}
		Label label3 = (Label)this.rptList.Controls[this.rptList.Controls.Count - 1].FindControl("lblTotalCount");
		Label label4 = (Label)this.rptList.Controls[this.rptList.Controls.Count - 1].FindControl("lblTotalMoney");
		label3.Text = d.ToString();
		label4.Text = d2.ToString();
		string url = this.beforeUrl + this.linkHead + "&pageindex";
		this.ltrPagePanel.Text = CurrPageLinks.instance.CurrPageLinkStr(num, num2, listCount, "条记录&nbsp;每页" + num2 + "条记录&nbsp;", url, true);
	}
	protected void btnSearch_Click(object sender, EventArgs e)
	{
		this.BindData();
	}
}
